package model;

import java.net.UnknownHostException;

import com.google.code.morphia.Morphia;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class DBConnection {
	
	private static Mongo m = null;
	private static final String host = "174.142.68.9";
	private static final String database = "garden";
	private static Morphia morphia = null;

	public static Mongo getMongo() {
		if (m == null) {
			try {
				m = new Mongo(host);
			} catch (UnknownHostException e) {
				// TODO Auto-generated catch block
			} catch (MongoException e) {
				// TODO Auto-generated catch block
			}
		}
		return m;
	}

	public static String getDatabase() {
		return database;
	}

	public static Morphia getMorphia() {
		if (morphia == null) {
			morphia = new Morphia();
		}
		return morphia;
	}

//	static Mongo m = null;
//	static DB db = null;
//
//	public static DBCollection data(String name) {
//		if (m == null) {
//			try {
//				m = new Mongo("184.107.58.9");
//			} catch (UnknownHostException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (MongoException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		DBCollection coll = null;
//		if (db == null) {
//			db = m.getDB("garden");
//			coll = db.getCollection(name);
//		} else {
//			coll = db.getCollection(name);
//		}
//		return coll;
//	}
}
